<?php
/**
 * 网站编辑
 */
$title = '购物车设置';
include "header.php";
$method = explode(',', $conf['CartPaySet']);
?>
<div class="row">
    <div class="col-xl-12">
        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                        <h3 class="mb-3 header-title text-success"><?= $title ?></h3>
                        <form class="form-horizontal layui-form">
                            <div class="form-group mb-2">
                                <label for="example-input-normal">支持的付款方式</label>
                                <div class="">
                                    <?php
                                    $met = 0;
                                    $method_name = ['支付宝', '微信', 'QQ钱包', '余额', '积分兑换'];
                                    foreach ($method_name as $v) {
                                        ?>
                                        <input type="checkbox" name="CartPaySet[]"
                                               lay-skin="primary" value="<?= ($met + 1) ?>" lay-filter="CartPaySet"
                                               title="<?= $method_name[$met] ?>"
                                               <?= in_array(($met + 1), $method) ? ' checked=""' : null ?>>
                                        <?php $met++;
                                    } ?>
                                </div>
                            </div>

                            <div class="form-group mb-3" style="">
                                <label for="example-input-normal"
                                       style="position: relative;bottom: 0;left: 0">购物车收银台公告 (纯文字即可)</label>
                                <textarea class="form-control" name="CartNotice" id="CartNotice" rows="6"
                                          placeholder="请输入购物车收银台公告"><?= $conf['CartNotice'] ?></textarea>
                            </div>

                            <button type="submit" lay-submit lay-filter="Web_editor"
                                    class="btn btn-block btn-xs btn-success">保存内容
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<?php include "bottom.php"; ?>

<script>
    layui.use('form', function () {
        var form = layui.form;
        form.on('submit(Web_editor)', function (data) {
            var a = '';
            array = new Array();
            $.each(data.field, function (key, val) {
                if (key != 'CartNotice') {
                    if(this[0]==undefined)return;
                    a += ',' + this[0]
                }
            });
            if (a != '') {
                a = a.substr(1, a.length);
            }
            layer.alert('是否要执行当前操作？', {
                icon: 3, btn: ['确定', '取消'], btn1: function (layero, index) {
                    var index = layer.msg('数据保存中,请稍后...', {icon: 16, time: 999999});
                    $.post('ajax.php?act=config_set', {
                        CartPaySet: a,
                        CartNotice: data.field['CartNotice']
                    }, function (res) {
                        if (res.code == 1) {
                            layer.close(index);
                            layer.alert(res.msg, {
                                btn1: function (layero, index) {
                                    location.reload();
                                }
                            });
                        } else {
                            layer.close(index);
                            layer.alert(res.msg, {
                                btn1: function (layero, index) {
                                    location.reload();
                                }
                            });
                        }
                    });
                }
            });
            return false;
        })
    });
    layui.use(['upload', 'form'], function () {
        var upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            , url: 'ajax.php?act=image_up' //上传接口
            , done: function (res, index, upload) {
                layer.msg('图片上传成功');
                $("#image").val(res.src);
                $("#image_base").attr('src', res.src);
            }
            , error: function () {
                layer.msg('图片上传失败!')
            }
        });
    });
</script>